﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ResumeSharp;
using ResumeSharp.Data;

namespace ResumeSharp_Test
{
    /// <summary>
    ///This is a test class for MainFormTest and is intended
    ///to contain all MainFormTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MainFormTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        ///A test for Database
        ///</summary>
        [TestMethod()]
        public void DatabaseTest()
        {
            MainForm target = new MainForm(); // TODO: Initialize to an appropriate value
            ResumeSharpEntities expected = new ResumeSharpEntities();

            // Test the getter.
            ResumeSharpEntities actual = target.Database;
            Assert.AreEqual(expected, actual);

            target.Database = expected;
            Assert.AreSame(expected, actual);
        }

        /// <summary>
        ///A test for GetCurrentUser
        ///</summary>
        [TestMethod()]
        [DeploymentItem("ResumeBuilder.exe")]
        public void GetCurrentUserTest()
        {
            MainForm_Accessor target = new MainForm_Accessor(); // TODO: Initialize to an appropriate value

            string logon = Utilities.GetLogonId();
            ResumeSharpEntities db = new ResumeSharpEntities();
            var acctList = from acct in db.Account where acct.LogonId == logon select acct;

            Account expected = null;
            int numAccounts = acctList.Count();

            // Should only find 1 user
            Assert.AreEqual<int>(1, numAccounts, String.Format("Invalid number of accounts: {0}", numAccounts));
            if (numAccounts == 1)
                expected = acctList.First();
            Assert.IsNotNull(expected);
            Account actual = target.GetCurrentUser();
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for MainForm Constructor
        ///</summary>
        [TestMethod()]
        public void MainFormConstructorTest()
        {
            MainForm target = new MainForm();
            Assert.IsNotNull(target);
        }
    }
}
